function reallocEventProfile(p,nold,n)
  use derived,only:EventProfileTable
  implicit none

  type(EventProfileTable),pointer,dimension(:) :: &
       reallocEventProfile,p
  integer,intent(in) :: nold,n

  integer :: i,j,ierr

  allocate(reallocEventProfile(1:n),stat=ierr)
  if (ierr.ne.0) call abnormal_stop("reallocEventProfile",&
       "Memory allocation causes an error.")

  do i=1,n
     reallocEventProfile(i)%external_remain=0
     reallocEventProfile(i)%n_event=0
     reallocEventProfile(i)%n_alloc_event=0
     nullify(reallocEventProfile(i)%event_list)
  end do

  if (.not.associated(p)) return

  do i=1,nold
     reallocEventProfile(i)%event_type=p(i)%event_type
     reallocEventProfile(i)%index=p(i)%index
     reallocEventProfile(i)%sqnc=p(i)%sqnc
     reallocEventProfile(i)%external_remain=&
          p(i)%external_remain
     reallocEventProfile(i)%n_event=p(i)%n_event
     reallocEventProfile(i)%n_alloc_event=&
          p(i)%n_alloc_event
     reallocEventProfile(i)%rate_const=&
          p(i)%rate_const
     if (p(i)%n_alloc_event.gt.0) then
        allocate(reallocEventProfile(i)%event_list(&
             p(i)%n_alloc_event))
        do j=1,reallocEventProfile(i)%n_event
           reallocEventProfile(i)%event_list(j)=&
                p(i)%event_list(j)
        end do
        deallocate(p(i)%event_list)
     end if
  end do

  deallocate(p)

  return

end function reallocEventProfile
